import { reactive } from "vue";
import { AddUserContact, GetContactNum } from "@/api";

const AddressList = [
    {
        phone: "13611042909",
        address: "北京市昌平区回龙观镇龙域北街10号院1号楼4层413-414 (北京总部)",
    },
    {
        phone: "13533032272",
        address: "广州市天河区车陂街道车陂大岗路5号中侨基金小镇2栋",
    },
    {
        phone: "13025172727",
        address: "深圳市南山区桃园路田厦国际中心B座",
    },
    {
        phone: "0412-5297709",
        address: "辽宁省鞍山市高新区越岭路",
    },
    {
        phone: "13611042909",
        address: "太原市小店区金茂大厦B座25层",
    },
    {
        phone: "13611042909",
        address: "西安市雁塔区太白南路甲字6号上上国际城",
    },
    {
        phone: "0085296742710",
        address: "香港新界沙田区",
    },
];

const QrCodeList = [
    {
        name: "微信小程序",
        image: `${_oss_}images/footer/wxxiaochengxu.png`,
    },
    {
        name: "官方微博",
        image: `${_oss_}images/footer/weibo.png`,
    },
    {
        name: "公众号",
        image: `${_oss_}images/footer/gzh.png`,
    },
    {
        name: "抖音号",
        image: `${_oss_}images/footer/douyin.png`,
    },
    {
        name: "今日头条",
        image: `${_oss_}images/footer/toutiao.png`,
    },
];

const NavList = [
    {
        title: "首页",
        link: "/",
    },
    {
        title: "模版库",
        link: "/template.html",
    },
    {
        title: "用户发布（UGC）",
        link: "/worksSquare.html",
    },
    {
        title: "企业案例（PGC）",
        link: "/case.html",
    },
    {
        title: "新闻动态",
        link: "/news.html",
    },
    {
        title: "操作手册",
        link: "/help.html",
    },
    {
        title: "云空间",
        link: "/vrDownload.html",
    },
    {
        title: "关于我们",
        link: "/aboutMe.html",
    },
];

export const useContent = () => {
    const contactInfo = reactive({
        name: "",
        phone: "",
        demand: "",
        company: "",
    });

    const num = ref(0);

    const onLeaveMessage = async () => {
        if (isEmpty(contactInfo.name)) {
            Message().warning("请输入姓名");
        } else if (isEmpty(contactInfo.phone)) {
            Message().warning("请输入手机号");
        } else if (!/^[+-\d]{11,}$/.test(contactInfo.phone)) {
            Message().warning("请输入正确的手机号");
        } else if (isEmpty(contactInfo.demand)) {
            Message().warning("请输入需求");
        } else if (isEmpty(contactInfo.company)) {
            Message().warning("请输入公司/行业");
        } else {
            const res = await AddUserContact({
                phone: contactInfo.phone,
                name: contactInfo.name,
                demand: contactInfo.demand,
                company: contactInfo.company,
            });

            if (res.code == 200) {
                contactInfo.name = "";
                contactInfo.phone = "";
                contactInfo.demand = "";
                contactInfo.company = "";
                Message().success("留言成功，我们会有专门的人员联系您！");
                GetNum();
            }
        }
    };

    const GetNum = async () => {
        const res = await GetContactNum();
        if (res.code == 200) {
            num.value = res.data;
        }
    };

    return {
        NavList,
        QrCodeList,
        contactInfo,
        AddressList,
        num,
        GetNum,
        onLeaveMessage,
    };
};
